﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：StockRoomList.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：仓库物品显示（包括通过物品分类）
 * 作者：侯建
 * 创建日期：2011.04.15
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Jxym.DBUtility;

namespace Jxym.wlkc2011.Module.Default.server.StockRoom
{
    public partial class StockRoomList : System.Web.UI.Page
    {
        int type;
        string name = "";
        string starttime = "";
        string endtime = "";
        MsSqlDal<model.StockRoom> iStockRoom = new MsSqlDal<model.StockRoom>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["Type2"] != null)
                {
                    if (Request.Params["limit"] != null && Request.Params["start"] != null)
                    {

                        type = Convert.ToInt32(Request.Params["Type2"]);
                        if (type == 1)
                        {
                            if (Request.Params["Name"] != null)
                            {
                                name = Request.Params["Name"];
                            }
                            PageBean pb = new PageBean();
                            IList<model.StockRoom> list = iStockRoom.GetPageList("StockRoomName like '%" + name + "%'", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            pb.Count = iStockRoom.GetPageCount("StockRoomName like '%" + name + "%'", null);
                            pb.List = list;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                        else
                        {

                            if (Request.Params["StartTime"] != null)
                            {
                                starttime = Request.Params["StartTime"];

                            }
                            if (Request.Params["endtime"] != null)
                            {
                                endtime = Request.Params["endtime"];
                            }
                            PageBean pb = new PageBean();
                            IList<model.StockRoom> list = iStockRoom.GetPageList("StockRoomTime between '" + starttime + "' and '" + endtime + "'", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            pb.Count = iStockRoom.GetPageCount("StockRoomTime between '" + starttime + "' and '" + endtime + "'", null);
                            pb.List = list;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                    }
                }
                else
                {
                    if (Request.Params["limit"] != null && Request.Params["start"] != null)
                    {
                        if (Request.Params["ClassId"] != null)
                        {
                            int classid = Convert.ToInt32(Request.Params["ClassId"]);
                            MsSqlDal<model.StockRoom> iNotice = new MsSqlDal<model.StockRoom>();
                            IList<model.StockRoom> List = iNotice.GetPageList("PurchaseType = " + classid, null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            PageBean pb = new PageBean();
                            pb.Count = iNotice.GetPageCount("PurchaseType = " + classid, null);
                            pb.List = List;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                        else
                        {
                            MsSqlDal<model.StockRoom> iNotice = new MsSqlDal<model.StockRoom>();
                            IList<model.StockRoom> List = iNotice.GetPageList("", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            PageBean pb = new PageBean();
                            pb.Count = iNotice.GetPageCount("", null);
                            pb.List = List;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                        }
                    }
                    else
                    {
                        Response.Write("{'Count':0,'List':[]}");
                    }
                }
            }
        }
    }
}